package com.hrm.service.impl;

import com.hrm.dao.HrmApartmentMapper;
import com.hrm.dao.HrmStaffMapper;
import com.hrm.model.HrmApartment;
import com.hrm.service.HrmApartmentService;
import com.hrm.util.PageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("hrmApartmentService")
public class HrmApartmentServiceImpl implements HrmApartmentService{
    @Autowired
    protected HrmStaffMapper hrmStaffMapper;
    @Autowired
    protected HrmApartmentMapper hrmApartmentMapper;

    @Override
    public PageView findEntityPageByParam(PageView pageView, Map<String, Object> param) {
        param.put("offset", pageView.getFirstResult());
        param.put("limit", pageView.getPageSize());
        pageView.setQueryResult(hrmApartmentMapper.getPageNumByMap(param),
                hrmApartmentMapper.getPageByMap(param));
        return pageView;
    }
    @Override
    public int updateApartInfo(HrmApartment hrmApartment){
        return hrmApartmentMapper.updateByPrimaryKeySelective(hrmApartment);
    }

    @Override
    public HrmApartment getHrmApart(Integer id) {
        return hrmApartmentMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deleteApartById(Integer id) {
        hrmApartmentMapper.deleteByPrimaryKey(id);
        hrmStaffMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<HrmApartment> getHrmApartment() {
        Map<String, Object> params = new HashMap<String, Object>();
        return hrmApartmentMapper.getPageByMap(params);
    }
}
